package com.yanghui.dtracing.core.opentracing.reporter;

import com.yanghui.dtracing.core.opentracing.DTracerSpan;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

public class CompositionReporter implements Reporter{

    @Setter
    List<Reporter> reporterList = new ArrayList<>();

    @Override
    public void init() {
    }

    @Override
    public void report(DTracerSpan span) {
        if(!span.context().isSampled()){
            return;
        }
        try{
            for(Reporter reporter : reporterList){
                reporter.report(span);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public void close() {
        reporterList.forEach(item -> {
            item.close();
        });
    }
}
